package com.tofacebook.jdbc.maper;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

@Repository
public interface BookMapper {
    /**
     * 查询图书的价格
     * @param bookId
     * @return
     */
    @Select("select price from t_book where book_id = #{bookId}")
    Integer getPriceByBookId(@Param("bookId") Integer bookId);
    /*
     更新图书的库存
     */
    @Update("update t_book set stock = stock - 1 where book_id = #{bookId}")
    void updateStock(@Param("bookId") Integer bookId);

    /**
     * 更新用户的余额
     * @param userId
     * @param price
     */
    @Update("update t_user set balance = balance - #{price} where user_id =#{userId}")
    void updateBalance(@Param("userId") Integer userId,@Param("price") Integer price);
}
